//
//  EMMineItemView.m
//  EasyMoney
//
//  Created by 邓乐 on 2020/1/11.
//  Copyright © 2020 zh. All rights reserved.
//

#import "EMMineItemView.h"
#import "EMMineResponseModel.h"

@interface EMMineItemView ()

@property (nonatomic, strong) UIImageView *leftIcon;
@property (nonatomic, strong) UILabel *textLabel;
@property (nonatomic, strong) UILabel *subTextLabel;
@property (nonatomic, strong) UIImageView *arrowIcon;
@property (nonatomic, strong) UIView *bottomView;
@property (nonatomic, strong) UIButton *btn;

@property (nonatomic, strong) EMMineTabItemModel *model;

@end

@implementation EMMineItemView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        _leftIcon = [[UIImageView alloc] init];
        [self addSubview:_leftIcon];
        _textLabel = [[UILabel alloc] init];
        _textLabel.font = FONT_PINGFANG_REGULAR_(14);
        _textLabel.textColor = ColorFromRGB(0x333333);
        [self addSubview:_textLabel];
        _subTextLabel = [[UILabel alloc] init];
        _subTextLabel.font = FONT_PINGFANG_REGULAR_(15);
        _subTextLabel.textColor = ColorFromRGB(0x333333);
        [self addSubview:_subTextLabel];
        _arrowIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow_right"]];
        [self addSubview:_arrowIcon];
        _btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:_btn];
        [_btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
        _bottomView = [[UIView alloc] init];
        _bottomView.backgroundColor = ColorFromRGB(0xf8f8f8);
        _bottomView.hidden = YES;
        [self addSubview:_bottomView];
        
        [_leftIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(24, 24));
            make.left.equalTo(self).offset(20);
            make.centerY.equalTo(self);
        }];
        
        [_textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(_leftIcon);
            make.left.equalTo(_leftIcon.mas_right).offset(14);
        }];
        
        [_arrowIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(24, 24));
            make.centerY.equalTo(self);
            make.right.equalTo(self).offset(-20);
        }];
        
        [_subTextLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(_arrowIcon.mas_left);
            make.centerY.equalTo(_arrowIcon);
        }];
        
        [_bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(_textLabel.mas_left).offset(-5);
            make.right.mas_equalTo(self).offset(-15);
            make.bottom.equalTo(self);
            make.height.mas_equalTo(0.5);
        }];
        
        [_btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
    }
    return self;
}

- (void)clickBtn:(UIButton *)sender
{
    if (self.callback) {
        self.callback(0, self, self.model.action);
    }
}

- (void)updateWithDataModel:(id)dataModel callBack:(wdpCallBackBlock)callBack
{
    [super updateWithDataModel:dataModel callBack:callBack];
    EMMineTabItemModel *model = (EMMineTabItemModel *)dataModel;
    self.model = model;
    self.textLabel.text = model.leftTitle;
    self.subTextLabel.text = model.rightTitle;
    [self.leftIcon yy_setImageWithURL:[NSURL URLWithString:SAFE_STRING(model.icon)] placeholder:nil];
    self.bottomView.hidden = !model.hasBottomLine;
    self.wdpMarginUp = model.upperSpace;
    self.wdpMarginDown = model.lowerSpace;
    
}

@end
